package codingforgreat.class04;
// 本题测试链接 : https://leetcode.com/problems/maximum-subarray/
public class Class02_SubArrayMaxSum {
    public static int maxSubArray2(int[] arr) {
        if (arr == null || arr.length == 0) {
            return 0;
        }
       int pre = arr[0];
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            pre = Math.max(pre + arr[i], arr[i]);
            max = Math.max(max, pre);
        }
        return max;
    }
}
